﻿using FundHelper.Model;
using System.Diagnostics;
using System.IO;
using System.Net.Http.Json;
using System.Text.Json;
using System.Xml.Linq;

namespace FundHelper
{
    internal class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo dir = new("K线数据");
            string savePath = "各种指数.csv";
            string todayPath = "今日数据.csv";
            string testPath = "验证数据.csv";
            string testPath2 = "验证数据2.csv";
            init();
            if (File.Exists(savePath))
            {
                File.Delete(savePath);
            }
            if (File.Exists(testPath))
                File.Delete(testPath);
            if (File.Exists(todayPath))
                File.Delete(todayPath);
            for (int i = 0; i < dir.GetFiles().Length; i++)
            {
                var fileInfo = dir.GetFiles()[i];
                var data = ExploerData.Generagte(fileInfo.FullName);
                ExploerData.CalMark2(data, addHead:i==0, savePath, 200, 10);
                ExploerData.GetTest2(data, 180,addHead:i==0, testPath,removeEnd: 10, normalization:true);
                ExploerData.GetTest2(data, 5, addHead: i == 0, todayPath, removeEnd: 0, normalization: true);
            }
            Console.ReadLine();
        }
        static void init()
        {
            string jsonContent = File.ReadAllText("conf.json");
            var doc=JsonDocument.Parse(jsonContent);
            var sw = doc.RootElement.GetProperty("生物医药");
            // 反序列化JSON字符串到对象
            string[] keyName = ["AF5", "AF5Max", "AF5Min"];
            foreach(var key in keyName)
            {
                if (sw.TryGetProperty(key, out JsonElement je))
                    AFResult.AF5Dic.Add($"生物医药_{key}", je.Deserialize<double[]>()??new double[9]);
            }    

            sw.TryGetProperty("AF5Max", out JsonElement af5MaxJson);
            sw.TryGetProperty("AF5Mix", out JsonElement af5MinJson);


        }
    }

}
